/**
 * 音乐播放实例来实现适配器
 */

class VlcPlayer{
    static playVlc(filename){
        console.log(`I am playing vlc file ${filename}`)
    }
}

class Mp4Palyer{
   static playMp4(filename){
        console.log(`I am playing mp4 file ${filename}`)
    }
}

//适配器
class Adapter{
    play(audioType,filename){
        switch(audioType){
            case 'vlc':
                VlcPlayer.playVlc(filename)
                break
            case 'mp4':
                Mp4Palyer.playMp4(filename)
                break
            default:
                console.log('cannot play the type audio!')
        }
    }
}

//音乐播放器
class MusicPlayer{
    play(type,filename){
        switch(type){
            //播放音乐，不需要转换
            case 'mp3':
                console.log(`palying ${filename}!`)
                break
            //播放视频，需要通过适配器转换来播放视频中的声音
            case 'vlc':
            case 'mp4':
                this.adapter = new Adapter()
                this.adapter.play(type,filename)
                break
            default:
                console.log('cannot play the type music!')
        }
    }
}

const player = new MusicPlayer();

player.play("mp3", "beyond the horizon.mp3");
player.play("mp4", "alone.mp4");
player.play("vlc", "far far away.vlc");
player.play("avi", "mind me.avi");